/*
 * @Description: 路由鉴权组件(类似路由导航守卫)
 * @Author: Yong
 * @Date: 2021-09-27 16:33:56
 * @LastEditTime: 2021-09-27 16:50:50
 */
import { Redirect, Route } from 'react-router-dom'
import { isAuth } from '../../utils'


function AuthRoute ({ component: Component, ...rest }) {
    return (
        <Route
            {...rest}
            render={props => {
                const isLogin = isAuth()
                if (isLogin) {
                    return <Component {...props} />
                } else {
                    // 未登录跳转至登录页面 并传递来自那个页面的路由
                    return <Redirect to={{ pathname: '/login', state: { from: props.location } }} />
                }
            }}

        />
    )
}
export default AuthRoute